package com.tianshi.order.service.impl;


import com.tianshi.entity.OrderItems;
import com.tianshi.order.mapper.OrderItemMapper;
import com.tianshi.order.mapper.OrderMapper;
import com.tianshi.order.service.OrderItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@Slf4j
public class OrderItemServiceImpl implements OrderItemService {
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Autowired
    private OrderMapper orderMapper;



    @Override
    public List<OrderItems> getAllOrderItems()                                                                                                                                                                                                                                                                                                         {
        return orderItemMapper.selectAll();
    }

    @Override
    //删除订单项根据订单项
    public int deleteOrderItem(Long orderId) {
        OrderItems orderItems = orderItemMapper.selectByItemId(orderId);
        int i = orderItemMapper.deleteByItemId(orderId);
        if (i>0) {
            int i1 = orderMapper.deleteByOrderId(orderItems.getOrderId());
            if (i1>0){
                return i;
            }
        }
        return 0;
    }
    //根据orderId查询订单项
    @Override
    public List<OrderItems> checkOrderItemByOrderId(Long orderId) {
        return orderItemMapper.selectByOrderId(orderId);
    }


}


